use actix_web::web::Json;
use actix_web::web::HttpResponse;
use actix_web::Responder;
use contract::OrderUpdateRequest;
use log::info;

use crate::{domain::order_do::OrderUpdateDO, service::match_service};

#[get("/")]
async fn index()->impl Responder{
    format!("Endpoints: /match engine welcom! ")
}

/**
* 订单请求接口
*/
#[post("/streamorder/streamupdate")]
pub async fn add_order(order_update_request:Json<OrderUpdateRequest>) -> impl Responder {
    info!("订单修改请求:{:?}",order_update_request);
    //转换成内部对象.
    let order = OrderUpdateDO::new_from(order_update_request.0);
    
    info!("order is :{:?}",order);
    let place_order = match_service::on_order_update(order);
    HttpResponse::Ok().json(Some(place_order))
}